import Vue from "vue";
import Main from "./loading.vue";

if (typeof window !== "undefined" && window.Vue) {
  Vue = window.Vue;
}


const LoadingyConstructor = Vue.extend(Main);

//传入组件需要的参数
let LoadingDom=new LoadingyConstructor({
  el:document.createElement('div'),
  data(){
    return{
      
    }
  },
})

function ShowLoading(){  
  //向body节点添加组件
  LoadingDom.show=true;
  document.getElementById('app').appendChild(LoadingDom.$el);
}

function DeleteLoading(){  
  //删除节点
  LoadingDom.isdestroy=true;
  setTimeout(()=>{
    LoadingDom.show=false;
    document.getElementById('app').removeChild(LoadingDom.$el);
    LoadingDom=null;
  },300)
}

//向vue实例添加方法
function historyRegistry() {
  Vue.prototype.$ShowLoading = ShowLoading;
  Vue.prototype.$DeleteLoading = DeleteLoading;
}

export default historyRegistry;
